#include "ShapesSample.h"
#include "Game.h"
ShapesSample::ShapesSample(ID3D11Device* device, ID3D11DeviceContext* context) 
	: SampleBase(device,context),rotateSpeed(2.0f),radians(0.0f),index(0)
{
	m_Sphere = GeometricPrimitive::CreateSphere(context);
	m_Cone = GeometricPrimitive::CreateCone(context);
	m_Cube = GeometricPrimitive::CreateCube(context);
	m_Cylinder = GeometricPrimitive::CreateCylinder(context);
	m_Teapot = GeometricPrimitive::CreateTeapot(context);

	m_world = Matrix::Identity;
	m_view = Matrix::CreateLookAt(Vector3(2.f, 0.f, 2.f),
		Vector3::Zero, Vector3::UnitY);
	m_proj = Matrix::CreatePerspectiveFieldOfView(XM_PI / 4.f,
		16.0f/9.0f, 0.1f, 10.f);
	names.push_back("Sphere");
	names.push_back("Cone");
	names.push_back("Cube");
	names.push_back("Cylinder");
	names.push_back("Teapot");
}

ShapesSample::~ShapesSample()
{

}

void ShapesSample::Update(float dt)
{
	auto timer = Game::GetInstance()->GetTimer();
	auto time = static_cast<float>(timer->GetTotalSeconds());
	radians += dt * rotateSpeed;
	if (radians > XM_2PI)
	{
		dt = 0.0f;
	}
	m_world = Matrix::CreateRotationZ(radians);
}

void ShapesSample::Render()
{   
	switch (index)
	{
	case 0:
		m_Sphere->Draw(m_world, m_view, m_proj);
		break;
	case 1:
		m_Cone->Draw(m_world, m_view, m_proj);
		break;
	case 2:
		m_Cube->Draw(m_world, m_view, m_proj);
		break;
	case 3:
		m_Cylinder->Draw(m_world, m_view, m_proj);
		break;
	case 4:
		m_Teapot->Draw(m_world, m_view, m_proj);
		break;
	}
}

void ShapesSample::GUI()
{
	ImGui::Begin("Shapes");
	static const char* current_item = names[0].c_str();
	if (ImGui::BeginCombo("Primitives", current_item)) // The second parameter is the label previewed before opening the combo.
	{
		for (int n = 0; n < names.size(); n++)
		{
			bool is_selected = (current_item == names[n]); // You can store your selection however you want, outside or inside your objects
			if (ImGui::Selectable(names[n].c_str(), is_selected)) 
			{
				current_item = names[n].c_str();
				index = n;
				if (is_selected)
					ImGui::SetItemDefaultFocus();   // You may set the initial focus when opening the combo (scrolling + for keyboard navigation support)
			}
		}
		ImGui::EndCombo();
	}
	ImGui::SliderFloat("Rotate Speed",&rotateSpeed,0.1,10.0f);
	ImGui::End();
}

void ShapesSample::DrawFont()
{

}
